package cz.proks.easyhelpdesk.gwt.place.base;

import java.util.LinkedList;
import java.util.List;

import com.google.gwt.place.shared.Place;

public abstract class AHelpdeskPlace extends Place implements HelpdeskPlace {
    private final List<String> placeValues = new LinkedList<String>();
        
    public List<String> getPlaceValues() {
        return placeValues;
    }
    
    protected void setPlaceValues(List<String> placeValues) {
        assertInitValues(placeValues);
        this.placeValues.clear();
        this.placeValues.addAll(placeValues);
    }
    
    protected void addValue(Object value) {
        if (value != null)
            placeValues.add(value.toString());
    }
    
    protected void addValues(Object... values) {
        if (values != null)
            for (Object value : values)
                addValue(value);
    }
    
    protected void clearValues() {
        placeValues.clear();
    }
    
    protected void assertInitValues(List<String> initValues) {
        assertInitValues(initValues, 0);
    }
    
    protected void assertInitValues(List<String> initValues, int expectedValueCount) {
        if (initValues == null || initValues.size() < expectedValueCount)
            throw new IllegalStateException("InitValues are null or the size is incorrect! Size is " + (initValues != null ? initValues.size() : "-1") + ", expected size is " + expectedValueCount);
    }
}
